import {getCurrentInstance, reactive} from "vue";
import useTable from "@/views/system/role/hooks/useTable";
import moment from "moment"
import {RoleSearchForm} from "@/api/system/role";
export const searchForm = reactive<RoleSearchForm>({
    roleName:'',
    roleDesc:'',
    createTimeRange:[],
    updateTimeRange:[],
    dataStatus:undefined,
    page:1,
    pageSize:10
})
export default function useSearchForm() {
    const {getRoleDataList}= useTable()
    const instance = getCurrentInstance()
    function handleSearch() {
        searchForm.page = 1
        searchForm.createTimeRange = searchForm.createTimeRange?.map((d)=>{
            return moment(d).format("YYYY-MM-DD")
        })
        searchForm.updateTimeRange = searchForm.updateTimeRange?.map(d=>{
            return moment(d).format("YYYY-MM-DD")
        })
        getRoleDataList()
    }
    function resetSearchForm() {
        //eslint-disable-next-line
        (instance?.refs.searchFormRef as any).resetFields()
        searchForm.page = 1;
        searchForm.pageSize = 10;
        getRoleDataList()
    }
    return {
        searchForm,
        handleSearch,
        resetSearchForm
    }
}
